<template>
  <div class="app-container">
    <!-- 收费单 -->
    <!-- 主表查询和其他操作 -->
    <el-form :inline="true" class="demo-form-inline filter">
      <div>
        <el-form-item label="实验日期">
          <el-date-picker v-model="alarmdate" type="daterange" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期" />
        </el-form-item>
        <el-form-item label="单号">
          <el-input v-model="listQuery.fbillno" clearable class="filter-item" placeholder="请输入单号" />
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="listQuery.fbillstate" clearable filterable class="filter-item" placeholder="请选择状态">
            <el-option v-for="item in getListfbillstate" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="课题组">
          <el-select v-model="listQuery.ftaskno" clearable filterable class="filter-item" placeholder="请选择课题组">
            <el-option v-for="item in getListftask" :key="item.ftaskno" :label="item.ftaskname" :value="item.ftaskno" />
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="客户名称">
          <el-select v-model="listQuery.fsiteNo" :disabled="this.$store.state.user.fsiteLevel == 3" clearable filterable
            placeholder="请选择客户名称">
            <el-option v-for="item in fsiteNoBelongOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="实验人员" style="margin-left: 70px">
          <div style="display:flex;justify-content:flex-start;align-items:center">
            <el-select style="display: inline-block" clearable filterable v-model="listQuery.fuseuser"
              class="filter-item" placeholder="请选择实验人员">
              <el-option v-for="item in getListforduserAll" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
            <i class="el-icon-search selectI" @click="searchDialoguse('search')" />
          </div>
        </el-form-item>
        <el-form-item>
          <el-button round size="medium" class="filter-item"
            :style="{ background: buttonColor.lookup, color: buttonColor.color }" @click="handleFilter">查找</el-button>
        </el-form-item>
      </div>
    </el-form>

    <!-- 主表查询结果 -->
    <el-table :height="buttonColor.clientHeightTwo" v-loading="listLoading" :data="list" stripe
      element-loading-text="正在查询中。。。" border fit highlight-current-row :header-cell-style="tableColor">
      <el-table-column align="center" :width="buttonColor.operationTwo" label="操作" class-name="small-padding">
        <template slot-scope="scope">
          <div class="operationButton">
            <div :style="{ color: buttonColor.edit, cursor: 'pointer' }" @click="handleUpdate(scope.row)">
              <img src="../../../public/images/edit.png" />
              编辑
            </div>
            <div v-if="scope.row.fbillstate === 1 || scope.row.fbillstate === 0" :style="{ color: buttonColor.examine, cursor: 'pointer' }" @click="audit(scope.row)">
              <img src="../../../public/images/examine.png" />
              确定
            </div>
            <div v-else :style="{ color: buttonColor.examine, cursor: 'pointer' }">
              <img src="../../../public/images/examine.png" />
              确定
            </div>
            <!-- <div v-if="scope.row.fbillstate === 1" :style="{ color: buttonColor.invalid, cursor: 'pointer' }" @click="auditDelete(scope.row)">
              <img src="../../../public/images/invalid.png" />
              作废
            </div>
            <div v-else :style="{ color: buttonColor.invalid, cursor: 'pointer' }">
              <img src="../../../public/images/invalid.png" />
              作废
            </div> -->
          </div>
        </template>
      </el-table-column>
      <el-table-column :width="buttonColor.line" :index="indexMethod" align="center" label="序" type="index" />
      <el-table-column width="100" :formatter="dateFormat" align="left" label="实验日期" prop="frealbegtime" />
      <el-table-column width="160" align="left" label="单据编号" prop="fbillno" />
      <el-table-column :formatter="formatfpointNo" align="left" label="实验室" prop="fpointNo" />
      <el-table-column align="left" label="课题组" prop="ftaskname" />
      <el-table-column :formatter="formatfuseuser" :width="buttonColor.user" align="left" label="实验人员" prop="fuseuser" />
      <el-table-column align="right" label="本次消费" prop="fplanamt" />
      <el-table-column align="right" label="实际收费" prop="frealamt" />
      <el-table-column width="130" align="left" label="备注" prop="fexplanation" />
      <el-table-column align="left" :width="buttonColor.state" label="状态" prop="fbillstate">
        <template slot-scope="scope">
          <span :style="{ color: buttonColor.approval }" v-if="scope.row.fbillstate == 1">实验结束</span>
          <span :style="{ color: buttonColor.refused }" v-else-if="scope.row.fbillstate == 2">确认扣款</span>
          <span :style="{ color: buttonColor.order }" v-else>实验开始</span>
        </template>
      </el-table-column>
      <el-table-column :formatter="formatforduser" align="left" label="操作员" prop="foperator" />
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog :close-on-click-modal="false" :visible.sync="dialogFormVisible" width="80%">
      <template slot="title">
        <div :style="titleColor">{{ textMap[dialogStatus] }}</div>
      </template>
      <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="单据编号" prop="fbillno">
              <el-input disabled v-model="dataForm.fbillno" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="实验日期" prop="frealbegtime">
              <el-date-picker disabled v-model="dataForm.frealbegtime" type="date" placeholder="请选择实验日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item class="el-form-item-small" label="单据状态" prop="fbillstate">
              <el-select disabled v-model="dataForm.fbillstate" clearable filterable class="filter-item" placeholder="请选择状态">
            <el-option v-for="item in getListfbillstate" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="实验室" prop="fpointNo">
              <el-select disabled clearable filterable v-model="dataForm.fpointNo" class="filter-item"
                placeholder="请选择实验室">
                <el-option v-for="item in getListfpointNoAll" :key="item.value" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="人员" prop="fuseuser">
              <el-select disabled style="display: inline-block" clearable filterable v-model="dataForm.fuseuser"
              class="filter-item" placeholder="请选择人员">
              <el-option v-for="item in getListforduserAll" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="本次消费" prop="fplanamt">
              <el-input disabled v-model="dataForm.fplanamt" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="16">
            <el-form-item class="text" style="width: 100%" label="备注" prop="fexplanation">
              <el-input v-model="dataForm.fexplanation" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item class="el-form-item-small required" label="实际消费" prop="frealamt">
              <el-input disabled v-model="dataForm.frealamt" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div :style="{ width: '100%', display: 'flex', border: '2px solid #F2F2F2', height: panelHeight }">
        <el-tabs style="width: 100%" type="border-card">
          <el-tab-pane label="收费列表">
            <div class="app-container">
              <!-- 查询结果 -->
              <el-table :height="panelHeight" v-loading="listLoading" :data="dataForm.details" stripe
                element-loading-text="正在查询中。。。" border fit highlight-current-row :header-cell-style="tableColor">
                <el-table-column :index="indexMethod" align="center" label="序" type="index" />
                <el-table-column width="120" align="left" label="收费名称" prop="fchargeitem" />
                <el-table-column width="180" align="left" label="收费科目" prop="fchargeinfo" />
                <el-table-column width="80" align="right" label="使用数量" prop="fchargeqty" />
                <el-table-column width="160" :formatter="datetimeFormat" align="left" label="开始时间"
                  prop="frealbegtime" />
                <el-table-column width="160" :formatter="datetimeFormat" align="left" label="结束时间"
                  prop="frealendtime" />
                <el-table-column width="80" align="right" label="本次消费" prop="fplanamt" />
                <el-table-column width="80" align="right" label="实际消费" prop="frealamt" />
                <el-table-column align="left" label="备注" prop="fmemo" />
                <el-table-column v-if="isEdit" :width="buttonColor.operationTwo" align="center" label="操作" class-name="small-padding">
                  <template slot-scope="scope">
                    <div class="operationButton">
                      <div :style="{ color: buttonColor.edit, cursor: 'pointer' }" @click="handleEdit1(scope.row)">
                        <img src="../../../public/images/edit.png" />
                        编辑
                      </div>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button round size="medium" :style="{ background: buttonColor.cancel, color: buttonColor.colorone }"
          @click="dialogFormVisible = false">取消</el-button>
        <el-button v-if="isEdit" round size="medium" :style="{ background: buttonColor.confirm, color: buttonColor.color }"
          @click="updateData">确定</el-button>
      </div>
    </el-dialog>

    <!-- 子表修改 -->
    <el-dialog width="auto" top="0vh" :close-on-click-modal="false" :visible.sync="dialogFormVisibleOrder">
      <template slot="title">
        <div :style="titleColor">{{ textMap[dialogStatus] }}</div>
      </template>
      <el-form ref="dataFormOrder" :model="dataForm1" status-icon label-position="left" label-width="auto">
        <el-row>
          <el-col :span="8">
            <el-form-item label="收费名称" prop="fchargeitem">
              <el-input disabled v-model="dataForm1.fchargeitem" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="收费项目" prop="fchargeinfo">
              <el-input disabled v-model="dataForm1.fchargeinfo" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="使用数量" prop="fchargeqty">
              <el-input disabled v-model="dataForm1.fchargeqty" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="本次消费" prop="fplanamt">
              <el-input disabled v-model="dataForm1.fplanamt" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="开始时间" prop="frealbegtime">
              <el-date-picker disabled v-model="dataForm1.frealbegtime" type="datetime" placeholder="请选择开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="结束时间" prop="frealendtime">
              <el-date-picker disabled v-model="dataForm1.frealendtime" type="datetime" placeholder="请选择结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item class="required" label="实际消费" prop="frealamt">
              <el-input v-model.number="dataForm1.frealamt" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item class="required" label="备注" prop="fmemo">
              <el-input v-model="dataForm1.fmemo" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button round :style="{ background: buttonColor.cancel, color: buttonColor.colorone }"
          @click="dialogFormVisibleOrder = false">取消</el-button>
        <el-button round :style="{ background: buttonColor.confirm, color: buttonColor.color }"
          @click="updateDataOrder">确定
        </el-button>
      </div>
    </el-dialog>

    <userDialog :searchVisibleuse.sync="searchVisibleuse" :fsiteNo.sync="userDialogFsiteNo" :tableColor="tableColor"
      @userDialog="userDialogValue" />
  </div>
</template>

<style>
.button-margin {
  margin: 2px 0px;
}

.el-button+.el-button {
  margin-left: 1px;
}
</style>

<script>
/**
 * 引入api
 * 引入组件
 */
import { listchargeHead, updatechargeHead, deletechargeHead } from "@/api/labOrder/chargeHead";
import { listchargeDetail, updatechargeDetail } from "@/api/labOrder/chargeDetail";
import { listtsTask } from '@/api/labOrder/teamTask'
import { fsiteOptionsByLevel, getListArea, statusUpdate } from '@/api/area'
import Pagination from "@/components/Pagination";
import UserDialog from '@/components/UserDialog'
import moment from "moment";
import { tableColor, buttonColor, titleColor } from "@/filters/index";

const statusMap = {
  0: '未确认',
  1: '已确认'
}

export default {
  name: "MBill",
  components: { Pagination, UserDialog },
  filters: {
    statusFilter(type) {
      return statusMap[type]
    }
  },
  data() {
    return {
      fsiteNoBelongOptions: [], // 客户列表
      isEdit: true, // 编辑是否可以修改
      userFlag: null, // 判断人员是搜索还是添加
      searchVisibleuse: false, // 是否显示人员弹窗
      userDialogFsiteNo: null, // 客户编号(人员弹出框)
      getListftask: [], // 课题组列表
      getListfbillstate: [
        {label: '实验开始',value: '0'},
        {label: '实验结束',value: '1'},
        {label: '确认扣款',value: '2'},
      ], // 状态列表
      dialogFormVisibleOrder: false, // 编辑弹窗
      panelHeight: 0,
      getListforduserAll: [], //人员回显
      getListfpointNoAll: [], //地点回显
      getListfsiteNo: [], // 客户列表
      list: null,
      total: 0,
      listLoading: true,
      alarmdate: null,
      listQuery: {
        page: 1,
        limit: 20,
        fsiteNo: this.$store.state.user.fsiteNo,
        fbillno: undefined,
        fbillstate: undefined,
        ftaskno: undefined,
        fuseuser: undefined,
        minTime: undefined,
        maxTime: undefined,
        sort: "create_time",
        order: "desc",
      },
      statusMap,
      dataForm: {
        fbillno: undefined,
        fsiteNo: undefined,
        ftaskno: undefined,
        fuseuser: undefined,
        fusedate: undefined,
        fplanusedate: undefined,
        fpointNo: undefined,
        fmancount: undefined,
        fplanbegtime: undefined,
        fplanendtime: undefined,
        frealbegtime: undefined,
        frealendtime: undefined,
        fplanamt: undefined,
        frealamt: undefined,
        fexplanation: undefined,
        foperator: undefined,
        fbillstate: undefined,
        fbilltype: undefined,

        details: [
          {
            fbillno: undefined,
            fline: undefined,
            fchargeitem: undefined,
            fchargeinfo: undefined,
            fchargeqty: undefined,
            frealbegtime: undefined,
            frealendtime: undefined,
            fplanamt: undefined,
            frealamt: undefined,
            fmemo: undefined,
            foperator: undefined,
            fupddate: undefined,
          }
        ],
      },
      dataForm1: {
        fbillno: undefined,
        fline: undefined,
        fchargeitem: undefined,
        fchargeinfo: undefined,
        fchargeqty: undefined,
        frealbegtime: undefined,
        frealendtime: undefined,
        fplanamt: undefined,
        frealamt: undefined,
        fmemo: undefined,
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      tableColor,
      buttonColor,
      titleColor,
      rules: {
        fbillno: [
          { required: true, message: '单据编号不能为空', trigger: 'blur' }
        ],
      },
    };
  },
  created() {
    this.panelHeight = document.documentElement.clientHeight - 378
    // 查找日期默认当月一号至今天
    this.alarmdate = [this.parserDate(moment(new Date().setDate(1)).format('YYYY-MM-DD')), new Date()]
    // 获取查询列表数据
    this.getList();
    // 客户列表
    fsiteOptionsByLevel(3)
      .then(response => {
        this.fsiteNoBelongOptions = response.data.data.list
      })
      .catch(() => {
        this.fsiteNoBelongOptions = []
      })
    // 地点
    getListArea({ flag: 10, arg1: this.$store.state.user.fsiteNo })
      .then(response => {
        this.getListfpointNoAll = response.data.data.list
      })
      .catch(() => {
        this.getListfpointNoAll = []
      })
    // 人员
    getListArea({ flag: 13, arg1: this.$store.state.user.fsiteNo })
      .then(response => {
        this.getListforduserAll = response.data.data.list
      })
      .catch(() => {
        this.getListforduserAll = []
      })
    // 课题组
    listtsTask({ fsiteNo: this.$store.state.user.fsiteNo, limit: -1 })
      .then(response => {
        this.getListftask = response.data.data.list
      })
      .catch(() => {
        this.getListftask = []
      })

  },
  methods: {
    // 编辑弹窗
    updateDataOrder() {
      // 调用api保存编辑
      updatechargeDetail(this.dataForm1)
        .then(response => {
          let num = 0
          for (const v of this.dataForm.details) {
            if (v.fline === this.dataForm1.fline) {
              const index = this.dataForm.details.indexOf(v)
              this.dataForm.details.splice(index, 1, this.dataForm1)
              break
            }
          }
          this.dataForm.details.forEach((item)=>{
            console.log('v.frealamt',item.frealamt);
            num = num + Number(item.frealamt)
          })
          this.dataForm.frealamt = num
          this.dialogFormVisibleOrder = false
        })
        .catch((response) => {
          this.$notify.error({
            title: '失败',
            message: response.data.data
          })
        })
    },
    // 编辑弹窗
    handleEdit1(row) {
      console.log('eow', row);
      this.dataForm1 = Object.assign({}, row)
      this.dialogFormVisibleOrder = true
    },

    // 搜索人员弹出框
    searchDialoguse(value) {
      this.userFlag = value
      if (value === 'add') {
        this.userDialogFsiteNo = this.dataForm.fsiteNo
      } else {
        this.userDialogFsiteNo = this.listQuery.fsiteNo
      }
      this.searchVisibleuse = true
    },

    // 人员弹出框返回值
    userDialogValue(value) {
      console.log('value', value);
      if (this.userFlag === 'add') {
        this.dataForm.fperson = value.user.id.toString()
      } else {
        this.listQuery.fuseuser = value.user.id.toString()
      }
    },
    handleUpdate(row) {
      this.dataForm = Object.assign({}, row)
      if(this.dataForm.fbillstate == 1 || this.dataForm.fbillstate == 0){
        this.isEdit = true
      }else{
        this.isEdit = false
      }
      this.dataForm.fbillstate = this.dataForm.fbillstate.toString()
      listchargeDetail({ fbillno: this.dataForm.fbillno })
        .then((response) => {
          this.dataForm.details = response.data.data.list
          this.dialogStatus = 'update'
          this.dialogFormVisible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].clearValidate()
          })
        })
        .catch(() => {
          this.dataForm.details = [];
        });
    },
    updateData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          updatechargeHead(this.dataForm)
            .then(() => {
              for (const v of this.list) {
                if (v.fbillno === this.dataForm.fbillno) {
                  const index = this.list.indexOf(v)
                  this.list.splice(index, 1, this.dataForm)
                  break
                }
              }
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '更新收费单成功'
              })
            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response.data.msg
              })
            })
        }
      })
    },
    audit(row) {
      this.$confirm('是否确认此单号：' + row.fbillno, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.dataForm = Object.assign({}, row)
        statusUpdate({datatable:'m_tc_charge_head',fbillno:row.fbillno,type:2})
          .then(() => {
            for (const v of this.list) {
              if (v.fbillno === this.dataForm.fbillno) {
                this.dataForm.fbillstate = 2
                const index = this.list.indexOf(v)
                this.list.splice(index, 1, this.dataForm)
                break
              }
            }
            this.$notify.success({
              title: '成功',
              message: '确认成功'
            })
          })
          .catch((response) => {
            this.$notify.error({
              title: '失败',
              message: response.data.data
            })
          })
      })
    },
    auditDelete(row) {
      this.$confirm('是否作废此单号：' + row.fbillno, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.dataForm = Object.assign({}, row)
        statusUpdate({datatable:'m_tc_dailyaccount',fbillno:row.fbillno,type:3})
          .then(() => {
            for (const v of this.list) {
              if (v.fbillno === this.dataForm.fbillno) {
                this.dataForm.fbillstate = 3
                const index = this.list.indexOf(v)
                this.list.splice(index, 1, this.dataForm)
                break
              }
            }
            this.$notify.success({
              title: '成功',
              message: '作废成功'
            })
            this.selectList = []
          })
          .catch((response) => {
            this.$notify.error({
              title: '失败',
              message: response.data.data
            })
          })
      })
    },
    handleDelete(row) {
      this.$confirm('是否要删除收费单', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletechargeHead(row)
          .then((response) => {
            this.$notify.success({
              title: '成功',
              message: '删除收费单成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          })
          .catch((response) => {
            this.$notify.error({
              title: '失败',
              message: response
            })
          })
      })
    },
    // 存放地点
    formatfpointNo: function (row, column) {
      if (this.getListfpointNoAll) {
        for (let i = 0; i < this.getListfpointNoAll.length; i++) {
          if (row.fpointNo === this.getListfpointNoAll[i].value) {
            return this.getListfpointNoAll[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    // 客户回显
    formatfsiteNo: function (row, column) {
      if (this.getListfsiteNo) {
        for (let i = 0; i < this.getListfsiteNo.length; i++) {
          if (row.fsiteNo === this.getListfsiteNo[i].value) {
            return this.getListfsiteNo[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    formatfuseuser: function (row, column) {
      if (this.getListforduserAll) {
        for (let i = 0; i < this.getListforduserAll.length; i++) {
          if (row.fuseuser == this.getListforduserAll[i].value) {
            return this.getListforduserAll[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    // 人员
    formatforduser: function (row, column) {
      if (this.getListforduserAll) {
        for (let i = 0; i < this.getListforduserAll.length; i++) {
          if (row.foperator == this.getListforduserAll[i].value) {
            return this.getListforduserAll[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    // 日期回显
    dateFormat(row, column) {
      const date = row[column.property];
      if (date === undefined || date === null) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD");
    },
    // 日期回显
    datetimeFormat(row, column) {
      const date = row[column.property];
      if (date === undefined || date === null) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    // 日期格式化
    parserDate(date) {
      var t = Date.parse(date)
      if (!isNaN(t)) {
        return new Date(Date.parse(date.replace(/-/g, '/')))
      }
    },
    // 查找日期格式返回
    formatDate: function (date) {
      if (typeof (date) === 'object') {
        var ym
        var y = date.getFullYear()
        var m = date.getMonth() + 1
        var d = date.getDate()
        if (m < 10) {
          m = '0' + m
        }
        if (d < 10) {
          d = '0' + d
        }
        ym = y + '-' + m + '-' + d
        return ym
      } else {
        return date
      }

    },
    getList() {
      // 查找开始日期
      this.listQuery.minTime = this.alarmdate == null ? null : this.formatDate(this.alarmdate[0]) + '00:00:00'
      // 查找结束日期
      this.listQuery.maxTime = this.alarmdate == null ? null : this.formatDate(this.alarmdate[1]) + '23:59:59'
      this.listLoading = true;
      // 查找返回数据
      listchargeHead(this.listQuery)
        .then((response) => {
          this.list = response.data.data.list
          this.total = response.data.data.total
          this.listLoading = false
        })
        .catch(() => {
          this.list = [];
          this.total = 0;
          this.listLoading = false;
        });
    },
    // 查找
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    // 序号
    indexMethod(index) {
      index = index + 1;
      return index;
    },
  },
};
</script>
